www.gusucode.com > VC++ 客户管理系统(SQL Serve)-源码程序 > VC++ 客户管理系统(SQL Serve)-源码程序/code/Program/yuwl.cpp

    // yuwl.cpp : implementation file
//

#include "stdafx.h"
#include "khmanager.h"
#include "yuwl.h"
#include "ado.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int yuwlclnum=0;
int yuwlxiugai=0;
/////////////////////////////////////////////////////////////////////////////
// yuwl dialog


yuwl::yuwl(CWnd* pParent /*=NULL*/)
	: CDialog(yuwl::IDD, pParent)
{
	//{{AFX_DATA_INIT(yuwl)
	//}}AFX_DATA_INIT
}


void yuwl::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(yuwl)
	DDX_Control(pDX, IDC_DATETIMEPICKER1, m_date);
	DDX_Control(pDX, IDC_EDIT5, m_edit5);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_EDIT6, m_edit6);
	DDX_Control(pDX, IDC_EDIT4, m_edit4);
	DDX_Control(pDX, IDC_EDIT3, m_edit3);
	DDX_Control(pDX, IDC_EDIT2, m_edit2);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	DDX_Control(pDX, IDC_COMBO1, m_com1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(yuwl, CDialog)
	//{{AFX_MSG_MAP(yuwl)
	ON_COMMAND(ID_ADD, OnAdd)
	ON_COMMAND(ID_DELETE, OnDelete)
	ON_COMMAND(ID_EXIT, OnExit)
	ON_COMMAND(ID_UPDATE, OnUpdate)
	ON_COMMAND(ID_SAVE, OnSave)
	ON_COMMAND(ID_CANCEL, OnCancel)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// yuwl message handlers

BOOL yuwl::OnInitDialog() 
{
	CDialog::OnInitDialog();
	ado load;
	load.Open("select * from tb_khxx",adCmdText);
	int rstnum=load.GetRecordCount();
	int l;
	for(l=1;l<=rstnum;l++)
	{
		this->m_com1.AddString(load.GetFieldValue("khxx_mc"));
		load.Move(l);
		
	}

	load.close();
	
	imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON10)));
	
	CString s;
	TCHAR *pString;
	menu.LoadMenu(IDR_lxrxx);

	toolbar.EnableAutomation();
	toolbar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_TOOLBAR);
	toolbar.SetImageList(&imagelist);

	int i;
	for(i=0;i<8;i++)
	{
	button[i].dwData=0;
	button[i].fsState=TBSTATE_ENABLED;
	button[i].fsStyle=TBSTYLE_BUTTON;
	}
	button[5].fsStyle=TBSTYLE_SEP;
	button[0].idCommand=ID_ADD;
	button[0].iBitmap=0;
	button[1].idCommand=ID_UPDATE;
	button[1].iBitmap=1;
	button[2].idCommand=ID_DELETE;
	button[2].iBitmap=2;
	button[3].idCommand=ID_SAVE;
	button[3].iBitmap=3;
	button[4].idCommand=ID_CANCEL;
	button[4].iBitmap=4;
	button[6].idCommand=ID_EXIT;
	button[6].iBitmap=5;
for(i=0;i<8;i++)
{
	s.LoadString(i+IDS_21);
	int nStringLength= s.GetLength() + 1;
	pString = s.GetBufferSetLength(nStringLength);
	
	button[i].iString =toolbar.AddStrings(pString);
		s.ReleaseBuffer();
}
	toolbar.AddButtons(7,button);
	toolbar.AutoSize();
	toolbar.SetStyle(TBSTYLE_FLAT|CCS_TOP);
	toolbar.EnableButton(ID_SAVE,false);
	toolbar.EnableButton(ID_CANCEL,false);
	
		m_list.ModifyStyle(0L,LVS_REPORT);
//	m_list.ModifyStyle(0L,LVS_SINGLESEL);
	m_list.ModifyStyle(0L,LVS_SHOWSELALWAYS);
	m_list.ModifyStyle(0L,LVS_NOSORTHEADER);
	m_list.SetExtendedStyle(LVS_EX_GRIDLINES|
		LVS_EX_FULLROWSELECT|
		LVS_EX_HEADERDRAGDROP|
		LVS_EX_ONECLICKACTIVATE);
	m_list.InsertColumn(0,"产品销售编号");
	m_list.InsertColumn(1,"产品名称");
	m_list.InsertColumn(2,"产品单价");
	m_list.InsertColumn(3,"销售数量");
	m_list.InsertColumn(4,"业务量");
	m_list.InsertColumn(5,"客户名称");
	m_list.InsertColumn(6,"产品销售日期");
	m_list.InsertColumn(7,"备注信息");
	m_list.SetColumnWidth(0,100);
	m_list.SetColumnWidth(1,100);
	m_list.SetColumnWidth(2,100);
	m_list.SetColumnWidth(3,100);
	m_list.SetColumnWidth(4,100);
	m_list.SetColumnWidth(5,100);
	m_list.SetColumnWidth(6,100);
	m_list.SetColumnWidth(7,100);
	this->loadlist();
	this->enbalewin(false);
	this->datatotext();
	this->texttowin();
	this->m_date.EnableWindow(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void yuwl::OnAdd() 
{
	this->enbalewin(true);
	this->enablebutton(false);
	this->clearall();
	this->autonum();
	
}

void yuwl::OnCancel() 
{
	this->enbalewin(false);
	this->enablebutton(true);
	yuwlxiugai=0;
	this->datatotext();
	this->texttowin();
}

void yuwl::OnDelete() 
{
	ado rst;
	CString ss,aa;
	this->m_edit1.GetWindowText(aa);
	if(aa.IsEmpty())
	{MessageBox("不能为空","提示");
	return;}
	if(MessageBox("删除后数据将丢失","提示",MB_YESNO)==IDYES)
	{

		ss.Format("delete from tb_Client_cpxs where cpxs_id = '%s'",aa);
	rst.ExecuteSQL(ss);

m_list.DeleteAllItems();
this->loadlist();
this->datatotext();
this->texttowin();
	
	}
}
void yuwl::OnExit() 
{
this->EndDialog(true);
	
}

void yuwl::OnUpdate() 
{
	CString ss,aa;
	this->m_edit1.GetWindowText(aa);
	if(aa.IsEmpty())
	{MessageBox("不能为空","提示");
	return;}
		this->enbalewin(true);
	this->enablebutton(false);
	yuwlxiugai=1;
	
}

void yuwl::OnSave() 
{
	ado rst;
	this->wintotext();
	CString ss;
	if(yuwlxiugai==1)
	{ss.Format("UPDATE tb_Client_cpxs set cpxs_mc='%s',cpxs_cpdj='%s',cpxs_xssl='%s',cpxs_ywl='%s',cpxs_khmc='%s',cpxs_xsrq='%s',cpxs_bz='%s' where cpxs_id='%s'",edit4,edit2,edit5,edit6,com1,date,edit3,edit1);}
	else
	{ss.Format("INSERT INTO tb_Client_cpxs values('%s','%s','%s','%s','%s','%s','%s','%s')",edit1,edit4,edit2,edit5,edit6,com1,date,edit3);}
	rst.ExecuteSQL(ss);
	m_list.DeleteAllItems();
this->loadlist();
this->datatotext();
this->texttowin();
this->enbalewin(false);
	this->enablebutton(true);
	yuwlxiugai=0;
}
void yuwl::clearall()
{
	this->m_com1.SetWindowText("");
	this->m_edit1.SetWindowText("");
	this->m_edit2.SetWindowText("");
	this->m_edit3.SetWindowText("");
	this->m_edit4.SetWindowText("");
	this->m_edit5.SetWindowText("");
	this->m_edit6.SetWindowText("");
}
void yuwl::enablebutton(bool butn)
{
	toolbar.EnableButton(ID_ADD,butn);
		toolbar.EnableButton(ID_UPDATE,butn);
	toolbar.EnableButton(ID_DELETE,butn);
	toolbar.EnableButton(ID_SAVE,!butn);
	toolbar.EnableButton(ID_CANCEL,!butn);
}
void yuwl::enbalewin(bool wi)
{

	this->m_com1.EnableWindow(wi);
	this->m_edit1.EnableWindow(wi);
	this->m_edit2.EnableWindow(wi);
	this->m_edit3.EnableWindow(wi);
	this->m_edit4.EnableWindow(wi);
	this->m_edit5.EnableWindow(wi);
	this->m_edit6.EnableWindow(wi);
}
void yuwl::texttowin()
{
	this->m_date.SetWindowText(date);
	this->m_com1.SetWindowText(com1);
	this->m_edit1.SetWindowText(edit1);
	this->m_edit2.SetWindowText(edit2);
	this->m_edit3.SetWindowText(edit3);
	this->m_edit4.SetWindowText(edit4);
	this->m_edit5.SetWindowText(edit5);
	this->m_edit6.SetWindowText(edit6);
}
void yuwl::wintotext()
{
	this->m_date.GetWindowText(date);
	this->m_com1.GetWindowText(com1);
	this->m_edit1.GetWindowText(edit1);
	this->m_edit2.GetWindowText(edit2);
	this->m_edit3.GetWindowText(edit3);
	this->m_edit4.GetWindowText(edit4);
	this->m_edit5.GetWindowText(edit5);
	this->m_edit6.GetWindowText(edit6);
}
void yuwl::datatotext()
{
	edit1=m_list.GetItemText(yuwlclnum,0);
	edit2=m_list.GetItemText(yuwlclnum,2);
	edit3=m_list.GetItemText(yuwlclnum,7);
	edit4=m_list.GetItemText(yuwlclnum,1);
	edit5=m_list.GetItemText(yuwlclnum,3);
	edit6=m_list.GetItemText(yuwlclnum,4);
	com1=m_list.GetItemText(yuwlclnum,5);
	date=m_list.GetItemText(yuwlclnum,6);
}
void yuwl::loadlist()
{
		ado rst;
	rst.rstOpen("select * from tb_Client_cpxs");
	int recordcount=rst.GetRecordCount();
int ii;
for(ii=1;ii<=recordcount;ii++)
{
m_list.InsertItem(ii-1,"");
m_list.SetItemText(ii-1,0,rst.GetFieldValue("cpxs_id"));
m_list.SetItemText(ii-1,1,rst.GetFieldValue("cpxs_mc"));
m_list.SetItemText(ii-1,2,rst.GetFieldValue("cpxs_cpdj"));
m_list.SetItemText(ii-1,3,rst.GetFieldValue("cpxs_xssl"));
m_list.SetItemText(ii-1,4,rst.GetFieldValue("cpxs_ywl"));
m_list.SetItemText(ii-1,5,rst.GetFieldValue("cpxs_khmc"));
m_list.SetItemText(ii-1,6,rst.GetFieldValue("cpxs_xsrq"));
m_list.SetItemText(ii-1,7,rst.GetFieldValue("cpxs_bz"));
rst.Move(ii);
}
rst.close();
}
void yuwl::autonum()
{
	ado rst3;
	rst3.rstOpen("select * from tb_Client_cpxs");
		if(rst3.GetRecordCount()==0)
		{
this->m_edit1.SetWindowText("XS001");
this->m_edit1.EnableWindow(false);
return;
		}
	
	rst3.MoveLast();
	CString mm=rst3.GetFieldValue("cpxs_id");
	int xuhao=atoi(mm.Right(3));
	xuhao+=1;
	mm.Format("XS%03d",xuhao);
	this->m_edit1.EnableWindow(false);
	
	this->m_edit1.SetWindowText(mm);
	rst3.close();
}

void yuwl::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	yuwlclnum=m_list.GetHotItem();
	if(yuwlclnum<0)
	{return;}
	this->datatotext();
	this->texttowin();	
	this->enbalewin(false);
	this->enablebutton(true);
	
	*pResult = 0;
}

BOOL yuwl::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
		pMsg->wParam=9;		
	return CDialog::PreTranslateMessage(pMsg);
}